<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.myfirefly.cn/tag/auth" prefix="auth"%>
<script type="text/javascript">
	var spfTradeReturnVisitDataGrid = $('#spfTradeReturnVisit-datagrid-json').datagrid({
		gridTitle : '回访管理',
	    showToolbar: true,
	    toolbarItem: '',
	    addLocation: 'first',
	    showLinenumber: false,
	    filterThead: false,
	    filterAll: true,
	    sortAll : true,
	    <auth:has funcId="spfTradeReturnVisit" action="/spfTradeReturnVisit/mlist.do">
	    dataUrl: 'spfTradeReturnVisit/mlist.do',
	    </auth:has>
	    dataType: 'json',
	    columns: [
	        {
				name: '',
				label: '操作',
				align: 'center',
				width: 130,
				quicksort:false,
				menu: false,
				edit: false,
				render: function(value){
			        var html = '';
			        <auth:has funcId="spfTradeReturnVisit" action="/spfTradeReturnVisit/show.do">
			    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-green btn-sm" onclick="showSpfTradeContractDetail(this)"><i class="fa fa-eye"></i> 查看</button></div>';
			    	</auth:has>
			    	<auth:has funcId="spfTradeReturnVisit" action="/spfTradeReturnVisit/add.do">
			    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-blue btn-sm" onclick="showspfTradeReturnVisit(this)"><i class="fa fa-edit"></i> 回访</button></div>';
				    </auth:has>
			    	return html;
				}
	        },
	        {
	            name: 'tradeContractStatus',
	            label: '状态',
	            type : 'select',
	            items: [{'1':'新建'}, {'2':'已录跟踪单'}, {'3':'已传网签合同未审核'}, {'4':'已传网签合同已审核'}, {'5':'已完成'}, {'6':'已取消'}],
	            align: 'center',
	            width: 220,
	            render: $.datagrid.renderItem
	        },
	        {
	            name: 'tradeRegion',
	            label: '成交区域',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'tradeShop',
	            label: '成交店面',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'tradePerson',
	            label: '成交人',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'belongShopManager',
	            label: '所属店经理',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'tradeAddress',
	            label: '成交地址',
	            align: 'center',
	            width: 220
	        },
	        {
	            name: 'customerName',
	            label: '客户姓名',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'contactWay',
	            label: '联系方式',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'identifyNum',
	            label: '证件号码',
	            align: 'center',
	            width: 180
	        },
	        {
	            name: 'tradeDate',
	            label: '成交日期',
	            type : 'date',
	            align: 'center',
	            width: 120,
	            render: function(val) {
	            	if(val){
	            		val = dateToStr('yyyy-MM-dd', new Date(val));
	            	}
	            	return val;
	            }
	        },
	        {
	            name: 'receivableCommission',
	            label: '应收佣金',
	            type : 'number',
	            align: 'center',
	            width: 120
	        },
	        {
	            name: 'hasAptitude',
	            label: '有无资质',
	            type : 'select',
	            items:[
	            	{'1':'有'},
	            	{'0':'无'}
	            ],
	            align: 'center',
	            width: 120,
	            render: $.datagrid.renderItem
	        },
	        
	        {
	            name: 'aptitudeHandleType',
	            label: '资质办理方式',
	            type : 'select',
	            items:[
	            	{'GS':'公司办理资质'},
	            	{'ZX':'自行办理资质'},
	            	{'SF':'三方办理资质'},
	            	{'QT':'其他'}
	            ],
	            align: 'center',
	            width: 160,
	            render: $.datagrid.renderItem
	        },
	        
	        {
	            name: 'aptitudeHandleTypeRemark',
	            label: '资质办理方式详情',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'buyType',
	            label: '认购方式',
	            type : 'select',
	            items:[
	            	{'QK':'全款'},
	            	{'DK':'贷款'},
	            	{'FQ':'分期'}
	            ],
	            align: 'center',
	            width: 120,
	            render: $.datagrid.renderItem
	        },
	        
	        {
	            name: 'buyTypeRemark',
	            label: '认购方式详情',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'firstPayDate',
	            label: '交首付日期',
	            type : 'date',
	            align: 'center',
	            width: 120,
	            render: function(val) {
	            	if(val){
	            		val = dateToStr('yyyy-MM-dd', new Date(val));
	            	}
	            	return val;
	            }
	        },
	        
	        {
	            name: 'residentContact',
	            label: '驻场联络人',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'oldBeltNew',
	            label: '是否老带新',
	            type : 'select',
	            items:[
	            	{'1':'是'},
	            	{'0':'否'}
	            ],
	            align: 'center',
	            width: 120,
	            render: $.datagrid.renderItem
	        },
	        
	        {
	            name: 'oldCustomerName',
	            label: '老客户姓名',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'oldCustomerIds',
	            label: '身份证号',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'oldCustomerContact',
	            label: '联系电话',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'oldCustomerBuyAddress',
	            label: '老客户所购房号',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'createBy',
	            label: '创建人',
	            align: 'center',
	            width: 120
	        },
	        
	        {
	            name: 'createDate',
	            label: '创建日期',
	            type : 'date',
	            pattern:'yyyy-MM-dd HH:mm:ss',
	            align: 'center',
	            width: 200,
	            render: function(val) {
	            	if(val){
	            		val = dateToStr('yyyy-MM-dd HH:mm:ss', new Date(val));
	            	}
	            	return val;
	            }
	        }
	    ],
	    afterSave: function($trs, datas) {
	        	this.refresh();
	        },
	    paging: {pageSize:20, selectPageSize:'20,30,40'},
	    showTfoot: true,
	    fullGrid: false,
	    toolbarCustom: function(){
	    	var html = '';
		    html += '<div class="btn-group" role="group"><button type="button" class="btn btn-green" onclick="refreshspfTradeReturnVisit()"><i class="fa fa-refresh"></i> 刷新</button></div>';
		    return html;
	    }
	});
	try {
		spfTradeReturnVisitDataGrid.data('bjui.datagrid').colLock(0, true);
	} catch (e) {
	}
	
	function refreshspfTradeReturnVisit() {
		spfTradeReturnVisitDataGrid.datagrid("refresh");
	}

	function showspfTradeReturnVisit(_this) {
		var index = $(_this).closest("tr").index();
		var data = spfTradeReturnVisitDataGrid.data('bjui.datagrid').getRowData(index);
		$('#edit-spfTradeReturnVisit-dialog').dialog({
			id:'edit-spfTradeReturnVisit-dialog',
			url:'spfTradeReturnVisit/add.do?contractId='+data.tradeContractId,
			maxable: false,
			mask: true,
			width: 850,
			height: 650,
			onLoad: function($dialog){
				setEditSpfTradeReturnVisitBtnEvent($dialog, true);
				// 根据data中的loginName，取得数据并加载到form表单中
				getJsonData2Form('spfTradeReturnVisit/getTrackForm.do', 'id='+data.id, $('#spfTradeReturnVisit_form'), spfTradeReturnVisitCallback);
				
			},
			
			title:'回访管理 - 添加'});
	}
	
	function showSpfTradeContractDetail(_this) {
		var index = $(_this).closest("tr").index();
		var data = spfTradeReturnVisitDataGrid.data('bjui.datagrid').getRowData(index);
		$('#edit-spfTradeReturnVisit-dialog').dialog({
			id:'edit-spfTradeReturnVisit-dialog',
			url:'spfTradeReturnVisit/show.do?contractId='+data.tradeContractId,
			maxable: false,
			mask: true,
			width: 850,
			height: 600,
			onLoad: function($dialog){
				var $cancel = $dialog.find('.cancel');
				$cancel.click(function(){
					$dialog.dialog('closeCurrent');
				});
				getJsonData2Form('spfTradeReturnVisit/getDetail.do', 'id='+data.tradeContractId, $('#spfTradeContract_form'), null);
			},
			
			title:'回访管理 - 成交合同详情'});
	}
	
	function spfTradeReturnVisitCallback($inputObj, _name, _val){
		if(_name == 'hasAptitude'){
			if(_val == '1') {
				$('#aptitudeHandleType1').show();
				$('#aptitudeHandleType2').show();
			} else if(_val == '0') {
				$('#aptitudeHandleType1').hide();
				$('#aptitudeHandleType2').hide();
			}
		}
	}
	
	function setEditSpfTradeReturnVisitBtnEvent($dialog, isAdd) {
		var $save, $cancel;
		$save = $dialog.find('.save');
		$cancel = $dialog.find('.cancel');
	
		$save.click(function(){
			$('#spfTradeReturnVisit_form').isValid(function(v) {
				if(v){
					var url = 'spfTradeReturnVisit/addSave.do';
					var data = $('#spfTradeReturnVisit_form').serialize();
					var successCallBack = function(){
						$dialog.dialog('closeCurrent');
						//refreshSpfTradeReturnVisit();
					}
					myAjax(url,	data, true,successCallBack,null);
				}
			});
		});
	
		$cancel.click(function(){
			$dialog.dialog('closeCurrent');
		});
	}
</script>
<div class="bjui-pageContent" id="spfTradeReturnVisit-index-pagecontent">
    <div style="padding:0px; height:100%; width:100%;">
        <table id="spfTradeReturnVisit-datagrid-json" data-width="100%" data-height="100%" class="table table-bordered">
        </table>
    </div>
</div>
<div id="edit-spfTradeReturnVisit-dialog" style="display: none;">
</div>
</div>